//
//  Label.cpp
//  Prism
//
//  Created by Bas du Pre on 24-05-11.
//  Copyright 2011 UU. All rights reserved.
//

#include "graphics/Label.h"

using namespace Prism;
using namespace Prism::Graphics;

Label::Label() {
    init();
    native_init();
}

Label::Label(const String & value) {
    setValue(value);
    setSize(16);
    setFont("Verdana");
    setColor(Color::White);
    setQuality(QualitySpeed);
    init();
    native_init();
    native_loadLabel();
}

Label::Label(const String & value, const String & font) {
    setValue(value);
    setSize(16);
    setFont(font);
    setColor(Color::White);
    setQuality(QualitySpeed);
    init();
    native_init();
    native_loadLabel();
}

Label::Label(const String & value, const String & font, PFloat size) {
    PRISM_ASSERT_FIX(size > 0, size = 16, "Size should be greater than 0");
    native_init();
    setValue(value);
    setSize(size);
    setFont(font);
    setColor(Color::White);
    setQuality(QualitySpeed);
    init();
    native_init();
    native_loadLabel();
}

Label::Label(const String &value, const String &font, PFloat size, const Color &color) {
    PRISM_ASSERT_FIX(size > 0, size = 16, "Size should be greater than 0");
    native_init();
    setValue(value);
    setSize(size);
    setFont(font);
    setColor(color);
    init();
    native_init();
    native_loadLabel();
}

Label::Label(const String & value, const String & font, PFloat size, const Color & color, Quality quality) {
    PRISM_ASSERT_FIX(size > 0, size = 16, "Size should be greater than 0");
    native_init();
    setValue(value);
    setSize(size);
    setFont(font);
    setColor(color);
    setQuality(quality);
    init();
    native_init();
    native_loadLabel();
}

Label::~Label() {
    //todo: native_unloadLabel();
}

void Label::init() {
    _color.onChange += delegate(this, &Label::_onColorChangeHandler);
}

void Label::setValue(const String & value) {
    if (_value == value) return;
    _value = value;
    EventArgs e;
    onValueChange(this, &e);
}

String Label::value() {
    return _value;
}

void Label::setFont(const String & font) {
    _font = font;
    EventArgs e;
    onFontChange(this, &e);
}

String Label::font() {
    return _font;
}

void Label::setQuality(Quality quality) {
    _quality = quality;
    EventArgs e;
    onQualityChange(this, &e);
}

Label::Quality Label::quality() {
    return _quality;
}

void Label::setSize(PFloat size) {
    PRISM_ASSERT_FIX(size > 0, size = 16, "Size should be greater than 0");
    _size = size;
    EventArgs e;
    onSizeChange(this, &e);
}

PFloat Label::size() {
    return _size;
}

void Label::setColor(const Color & color) {
    _color.copy(color);
    EventArgs e;
    onColorChange(this, &e);
}

Color &Label::color() {
    return _color;
}

void Label::_onColorChangeHandler(void*, EventArgs*) {
    EventArgs e;
    onColorChange(this, &e);
}

Prism::Rect Label::boundingBox() {
    return native_boundingBox();
}

String Label::toString() {
    return String("[Label value=\"") + _value + String("\"]");
}
